package br.ufla.pgcc.oomeasures.astvisitors;

import java.util.List;

import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public class AttributeVisitor extends ASTVisitor {
	
	private int numberOfClassAttributes;
	private int numberOfClassStaticAttributes;
	private int numberOfClassPrivateAttributes;
	private int numberOfClassPublicAttributes;
	private int numberOfClassProtectedAttributes;
	
	private static int numberOfProjectAttributes;
	private static int numberOfProjectPrivateAttributes;
	private static int numberOfProjectPublicAttributes;
	private static int numberOfProjectProtectedAttributes;
	
	@SuppressWarnings("unchecked")
	public boolean visit(FieldDeclaration variable) {
		
		numberOfClassAttributes++;
		numberOfProjectAttributes++;
		
		List<Modifier> modifiers = (List<Modifier>)variable.modifiers(); 
		
		for (Object modifier : modifiers) {
			
			if (modifier instanceof Modifier){
			
				ModifierKeyword modKeyword = ((Modifier) modifier).getKeyword();
				
				if (modKeyword.equals(ModifierKeyword.STATIC_KEYWORD)){ 
					numberOfClassStaticAttributes++;
					
				} else if (modKeyword.equals(ModifierKeyword.PRIVATE_KEYWORD)){ 
					numberOfClassPrivateAttributes++;
					numberOfProjectPrivateAttributes++;
					
				} else if (modKeyword.equals(ModifierKeyword.PROTECTED_KEYWORD)){ 
					numberOfClassProtectedAttributes++;
					numberOfProjectProtectedAttributes++;
					
				} else if (modKeyword.equals(ModifierKeyword.PUBLIC_KEYWORD)){ 
					numberOfClassPublicAttributes++;
					numberOfProjectPublicAttributes++;
				}
			}
		}				
		return false;
	}

	public int getNumberOfAttributes(){
		return numberOfClassAttributes;
	}
	
	public int getNumberOfStaticAttributes(){
		return numberOfClassStaticAttributes;
	}

	public int getNumberOfPrivateAttributes() {
		return numberOfClassPrivateAttributes;
	}

	public int getNumberOfPublicAttributes() {
		return numberOfClassPublicAttributes;
	}

	public int getNumberOfProtectedAttributes() {
		return numberOfClassProtectedAttributes;
	}
	
	public static int getNumberOfProjectAttributes(){
		return numberOfProjectAttributes;
	}
	
	public static int getNumberOfProjectPrivateAttributes() {
		return numberOfProjectPrivateAttributes;
	}

	public static int getNumberOfProjectPublicAttributes() {
		return numberOfProjectPublicAttributes;
	}

	public static int getNumberOfProjectProtectedAttributes() {
		return numberOfProjectProtectedAttributes;
	}
} 
